package czh.cocoa.animation;

import android.graphics.Camera;
import android.graphics.Matrix;
import czh.cocoa.foundation.NSObject;

public class CATransform3D extends NSObject {

	private Matrix mMatrix;
	
	private Camera mCamera;
	
	public CATransform3D() {
		mMatrix = new Matrix();
		mCamera = new Camera();  
	}
	
	public CATransform3D(CATransform3D t) {
		mMatrix = new Matrix(t.mMatrix);
		mCamera = new Camera();
	}

	public void translate(float tx, float ty, float tz) {
		mCamera.save();
		mCamera.translate(tx, -ty, tz);
		Matrix m = new Matrix();
		mCamera.getMatrix(m);
		mCamera.restore();
		
		mMatrix.preConcat(m);
	}
	
	public void scale(float sx, float sy, float sz) {
		mMatrix.preScale(sx, sy); //ignore sz
	}
	
	public void rotate(float degree, float x, float y, float z) {
		mCamera.save();
		
		if(x != 0) {
			mCamera.rotateX(degree);
		} else if(y != 0) {
			mCamera.rotateY(degree);
		} else if(z != 0) {
			mCamera.rotateZ(degree);
		}
		
		Matrix m = new Matrix();
		mCamera.getMatrix(m);
		mCamera.restore();
		
		mMatrix.preConcat(m);  
		
	}
	
	public void reset() {
		mMatrix.reset();
	}
	
	public Matrix getMatrix() {
		return mMatrix;
	}
	
	public boolean isIdentity() {
		return mMatrix.isIdentity();
	}
	
}
